package com.gugee.tiktok.web.repository;

import com.gugee.tiktok.web.dto.BloggerGrowth;
import com.gugee.tiktok.web.model.mysql.BloggerRecord;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface BloggerRecordRepository extends CrudRepository<BloggerRecord,Long> {

    BloggerRecord findTop1ByUidAndDatecode(long bloggerId,int dateCode);

    BloggerRecord findTop1ByUidOrderByDatecodeDesc(long bloggerId);

    List<BloggerRecord> findByUidAndDatecodeBetweenOrderByDatecodeDesc(long uid,int startDateCode,int endDateCode);

    @Query("SELECT " +
            "IFNULL(ROUND(SUM(follower_growth)),0) follower_growth, IFNULL(ROUND(SUM(like_total_count_growth)),0) like_growth,IFNULL(ROUND(SUM(share_growth)),0) share_growth," +
            "IFNULL(ROUND(SUM(review_growth)),0) review_growth,IFNULL(ROUND(SUM(follower_growth)),0) follower_count,IFNULL(ROUND(SUM(view_growth)),0) view_growth " +
            "FROM blogger_record where uid = :uid and datecode BETWEEN :startDateCode AND :endDateCode")
    BloggerGrowth findByGroupData(long uid, int startDateCode, int endDateCode);
}
